import axios from 'axios'

export const $http = (type, url, param, header) => {
  return new Promise((resolve, reject) => {
    if (type === 'post') {
      axios.post(url, param, header).then(res => resolve(res.data)).catch(err => reject(err))
    } else if (type === 'get') {
      url = url + '?'
      for (const key in param) {
        url = url + key + '=' + param[key]
      }
      axios.get(url, header).then(res => resolve(res.data)).catch(err => reject(err))
    } else {
      reject('请选择请求方式')
    }
  })
}
